﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace nwrole.toolbox.sync.extensions
{
    public static class DictionaryExtension
    {
        public static void Serialize(this IDictionary<long, long> data, string filePath)
        {
            using (var file = File.Create(filePath))
            {
                using (var writer = new BinaryWriter(file))
                {
                    writer.Write(data.Count);
                    foreach (var pair in data)
                    {
                        writer.Write(pair.Key);
                        writer.Write(pair.Value);
                    }
                }
            }
        }

        public static void Deserialize(this IDictionary<long, long> data, string filePath)
        {
            // TODO: what is this good for? 120924
            if (File.Exists(filePath))
            {
                using (var file = File.OpenRead(filePath))
                using (var reader = new BinaryReader(file))
                {
                    int count = reader.ReadInt32();
                    //string str = null;
                    //                 while (str = reader.ReadString())
                    //                {
                    //                    data.Add(str, reader.ReadInt32());
                    //                } 
                }
            }
        }

    }
}
